﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_10
{
    public partial class Form2 : Form
    {
        ListBox lbx2; // 用于接收Form1传递过来的候选名单
        Random rnd = new Random();
        public Form2(ListBox lbx)
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            label1.Text = "Ready？";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == false)
            {
                // 开始抽奖
                timer1.Enabled = true;
                button1.Text = "结束抽奖";
                label1.Text = "抽奖中...";
            }
            else
            {
                // 结束抽奖
                timer1.Enabled = false;
                button1.Text = "开始抽奖";
                MessageBox.Show($"恭喜 {label1.Text} 中奖！", "抽奖结果");
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (lbx2.Items.Count > 0)
            {
                int n = rnd.Next(lbx2.Items.Count);
                label1.Text = lbx2.Items[n].ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
